package com.aiks.dsyncpluginspringbootautoconfigure.plugin;


import com.aiks.dsyncpluginspringbootautoconfigure.BusinessException;
import com.aiks.dsyncpluginspringbootautoconfigure.pojo.ModuleConfigEntity;

import java.util.List;

/**
 * AbstractConvertPlugin.
 *
 * @author <a href="mailto:yuanz@yxt.com">yuanz</a>
 * @date 2022-06-27 17:31
 * @since 1.0.0
 **/
public abstract class AbstractFunctionPlugin<T> extends AbstractPlugin<T> {
    
    /**
     * handle.
     *
     * @param moduleConfig moduleConfig
     * @param saasData     saasData
     * @param clientDatas  clientDatas
     */
    protected abstract void handle(ModuleConfigEntity moduleConfig, List<T> saasData,
                                   List<Object> clientDatas);
    
    /**
     * execute.
     *
     * @param moduleConfig moduleConfig
     * @param saasDatas    saasDatas
     * @param clientDatas  clientDatas
     */
    @Override
    public void execute(final ModuleConfigEntity moduleConfig, final List<T> saasDatas,
                        final List<Object> clientDatas) {
        if (isExecute(moduleConfig, getPluginEnum())) {
            handle(moduleConfig, saasDatas, clientDatas);
        } else if (null != getNext()) {
            getNext().execute(moduleConfig, saasDatas, clientDatas);
        } else {
            throw new BusinessException("please check if the configuration is correct");
        }
    }
}
